package com.mall.group_booking.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.mall.common.response.CommonResponse;
import com.mall.entity.groupbooking.GbActivity;
import com.mall.group_booking.service.BookingActivityService;
import org.apache.commons.lang.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author White
 * @version 1.0
 * @email 616769721@qq.com
 * @date 2021/7/30 8:44
 */
@RestController
@RequestMapping("/bookingActivity")
@CrossOrigin
public class BookingActivityController {

    @Autowired
    private BookingActivityService bookingActivityService;


    @GetMapping("/addActivityToRedis")
    public void addActivityToRedis(){
        bookingActivityService.addActivityToRedis();
    }

    /**
     * 添加活动
     *
     * @return boolean
     */
    @PostMapping("/addActivity")
    public boolean addActivity(@RequestBody GbActivity activity) {
        try {
            bookingActivityService.addActivity(activity);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 查询拼团活动
     *
     * @param activity 活动
     * @param page     页面
     * @param size     大小
     * @return {@link PageInfo<GbActivity>}
     */
    @PostMapping("/findPage")
    private PageInfo<GbActivity> findPage(
            @RequestBody GbActivity activity,
            @RequestParam(value = "page",defaultValue = "1") int page,
            @RequestParam(value = "size",defaultValue = "5") int size
    ){
        return bookingActivityService.findPage(activity,page,size);
    }

    /**
     * 修改状态
     */
    @PutMapping("/updateStatusById")
    public boolean updateStatusById(Long id,String status) {
        try {
            bookingActivityService.updateStatusById(id, status);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    /**
     *
     */
    @PutMapping("/delActivityOne")
    public boolean delActivityOne(Long id) {
        try {
            bookingActivityService.delActivityOne(id);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

}
